package my.jieh.tips.io.serializable;

import java.io.Serializable;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */

public class SerializableRW implements Serializable {
  transient String keep_default = "Don't save me...";
	public static int a;
  String name;
  int servings;
  java.awt.Point point;

  public static void main(String args[]) {
    SerializableRW c = new SerializableRW();
    c.keep_default = "I changed...";
    c.a = 5;
    c.name = "Froot Loops";
    c.servings = 12;
    c.point = new java.awt.Point(20, 30);
    java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
    try {
      java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(baos);
      oos.writeObject(c);
      oos.close();
    } catch (java.io.IOException e) {
      System.err.println("Problems saving state");
    }
    java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(baos.toByteArray());
    try {
      java.io.ObjectInputStream ois = new java.io.ObjectInputStream(bais);
      SerializableRW c2 = (SerializableRW)ois.readObject();
      System.out.println("keep default: " + c2.keep_default);
      System.out.println("a:            " + c2.a);
      System.out.println("Name:         " + c2.name);
      System.out.println("Servings:     " + c2.servings);
      System.out.println("Point:        " + c2.point);
    } catch (ClassNotFoundException e) {
      System.err.println("Cannot find class to restore");
    } catch (java.io.IOException e) {
      System.err.println("Problems restoring state");
    }
  }
}